FROM 10.0.100.114/library/php-fpm:7.2

RUN apt-get update && apt-get install -y --no-install-recommends cron vim \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

COPY docker-entrypoint.sh /root/docker-entrypoint.sh

RUN touch /var/log/cron.log && \
    chown -R www-data:www-data /var/log/cron.log && \
    chmod a+x /root/docker-entrypoint.sh

ARG PHANTOMJS_VERSION=2.1.1

RUN set -ex; \
    ##
    # PhantomJS
    # Install phantomjs binary
    curl -LS "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2" -o phantomjs.tar.bz2; \
    mkdir -p phantomjs; \
    tar -xf phantomjs.tar.bz2 -C phantomjs --strip-components=1; \
    rm phantomjs.tar.bz2; \
    ( \
        cd phantomjs; \
        mv bin/phantomjs /usr/local/bin/ \
    ); \
    rm -r phantomjs; \
    chmod +rx /usr/local/bin/phantomjs

ONBUILD COPY . /var/www

ONBUILD RUN rm -f /var/www/bin/phantomjs; \
        ln -s /usr/local/bin/phantomjs /var/www/bin/phantomjs; \
        chown -R www-data:www-data /var/www; \
        find /var/www -type f -exec chmod 644 {} \;; \
        find /var/www -type d -exec chmod 755 {} \;

CMD ["/root/docker-entrypoint.sh"]